package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class ScrollTxtHor extends Sprite
	{
		private var _moveTxt:TextField;
		private var _showWid:Number = 200;
		
		private var thisAutoSize:String = TextFieldAutoSize.LEFT;
		
		public function ScrollTxtHor(autoSize:String = TextFieldAutoSize.LEFT)
		{
			init();
			
			thisAutoSize = autoSize;
		}
		
		private function init():void
		{
			_moveTxt = new TextField();
			_moveTxt.mouseEnabled = false;
			_moveTxt.autoSize = thisAutoSize;//"left";
			_moveTxt.multiline = false;
			
			this.addChild(_moveTxt);
		}
		
		public function label(value:String,color:uint = 0xfff100,font:int = 18,showBlack:Boolean = false):void
		{
			TextFieldUtils.setHtmlText(_moveTxt,HtmlText.formatSizeColor(value,color,font),true,showBlack);
			_moveTxt.autoSize = thisAutoSize;
			
			if(_moveTxt.width > _showWid)
			{
				var _mask2:Shape = new Shape();
				_mask2.graphics.clear();
				_mask2.graphics.beginFill(0);
				_mask2.graphics.drawRect(0,0,_showWid,_moveTxt.height);
				_mask2.graphics.endFill();
				addChild(_mask2);
				_moveTxt.mask = _mask2;
				this.addEventListener(Event.ENTER_FRAME,frameHandler);
			}
			
		}
		
		protected function frameHandler(event:Event):void
		{
			if(_moveTxt.x < - _moveTxt.width)
			{
				_moveTxt.x = _showWid;
			}else
			{
				_moveTxt.x = _moveTxt.x - 1;
			}
		}
		
		public function set showWid(value:Number):void
		{
			_showWid = value;
			_moveTxt.width = value;
		}
		
		override public function get width():Number
		{
			return _showWid;
		}
		
		public function clear():void
		{
			if(this.hasEventListener(Event.ENTER_FRAME)){
				this.removeEventListener(Event.ENTER_FRAME,frameHandler)
			}
		}
	}
}